package leetcode.weekly.week336;

import java.util.HashMap;
import java.util.Map;

//Solution3Test
public class Solution3 {
	public long beautifulSubarrays(int[] nums) {
		Map<Integer, Integer> cnts = new HashMap<>();
		long ans = 0;
		cnts.put(0, 1);
		for (int i = 0, s = 0; i < nums.length; i++) {
			int num = nums[i];
			s ^= num;
			ans += cnts.getOrDefault(s, 0);
			cnts.put(s, cnts.getOrDefault(s, 0) + 1);
		}
		return ans;
	}

}
